package org.idea.qiyu.framework.rpc.dubbo.router.starter.local.consumer;


import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.idea.qiyu.framework.rpc.dubbo.router.starter.local.service.ITestService;

import java.util.HashMap;

/**
 * @Author linhao
 * @Date created in 8:55 下午 2021/7/28
 */
public class TestConsumer {

    public static final String ZK_ADDR = "127.0.0.1:2181";

    public static void main(String[] args) throws InterruptedException {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("test-consumer-demo");
        applicationConfig.setParameters(new HashMap<>());
        applicationConfig.getParameters().putIfAbsent("zone", "master");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(ZK_ADDR);
        registryConfig.setProtocol("zoneAware");
        applicationConfig.setRegistry(registryConfig);

        ReferenceConfig<ITestService> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setApplication(applicationConfig);
        referenceConfig.setFilter("consumerContextFilter");
        referenceConfig.setInterface(ITestService.class);
        referenceConfig.setProtocol("dubbo");
        referenceConfig.setRegistry(registryConfig);
        while (true) {
            Thread.sleep(1000);
            System.out.println(referenceConfig.get().doTest());
        }
    }
}
